package com.erp.shop.controller;

import java.util.List;
import java.util.Arrays;

import com.erp.shop.domain.bo.ErpShopBindRecordBo;
import com.erp.shop.domain.vo.ErpShopBindRecordVo;
import com.erp.shop.service.IErpShopBindRecordService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

/**
 * 店铺绑定记录
 *
 * @author erp
 * @date 2024-05-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/shopBindRecord")
public class ErpShopBindRecordController extends BaseController {

    private final IErpShopBindRecordService iErpShopBindRecordService;

    /**
     * 查询店铺绑定记录列表
     */
//    @SaCheckPermission("system:shopBindRecord:list")
    @GetMapping("/list")
    public TableDataInfo<ErpShopBindRecordVo> list(ErpShopBindRecordBo bo, PageQuery pageQuery) {
        return iErpShopBindRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出店铺绑定记录列表
     */
//    @SaCheckPermission("system:shopBindRecord:export")
    @Log(title = "店铺绑定记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpShopBindRecordBo bo, HttpServletResponse response) {
        List<ErpShopBindRecordVo> list = iErpShopBindRecordService.queryList(bo);
//        ExcelUtil.exportExcel(list, "店铺绑定记录", ErpShopBindRecordVo.class, response);
    }

    /**
     * 获取店铺绑定记录详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:shopBindRecord:query")
    @GetMapping("/{id}")
    public R<ErpShopBindRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpShopBindRecordService.queryById(id));
    }

    /**
     * 新增店铺绑定记录
     */
//    @SaCheckPermission("system:shopBindRecord:add")
    @Log(title = "店铺绑定记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpShopBindRecordBo bo) {
        return toAjax(iErpShopBindRecordService.insertByBo(bo));
    }

    /**
     * 修改店铺绑定记录
     */
//    @SaCheckPermission("system:shopBindRecord:edit")
    @Log(title = "店铺绑定记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpShopBindRecordBo bo) {
        return toAjax(iErpShopBindRecordService.updateByBo(bo));
    }

    /**
     * 删除店铺绑定记录
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:shopBindRecord:remove")
    @Log(title = "店铺绑定记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpShopBindRecordService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
